package com.moolng.service.impl;

import com.moolng.entity.Order;
import com.moolng.service.ActonService;
import io.seata.core.context.RootContext;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author 李权
 * @description
 * @date 2021/1/6 18:22
 */
@Slf4j
@Service
public class ActonServiceImpl implements ActonService {
    
    
//    @Override
//    @GlobalTransactional
//    public boolean create(Order order) {
//        String xid = RootContext.getXID();
//        log.info("------->交易开始");
//        BusinessActionContext actionContext = new BusinessActionContext();
//        actionContext.setXid(xid);
//        boolean result = orderSaveImpl.saveOrder(actionContext, order);//订单服务prepare
//        if(!result){
//            throw new RuntimeException("保存订单失败");
//        }
//        //远程方法 扣减库存
//        log.info("------->扣减库存开始storage中");
//        result = storageApi.decrease(actionContext, order.getProductId(), order.getCount());//库存服务prepare
//        if(!result){
//            throw new RuntimeException("扣减库存失败");
//        }
//        log.info("------->扣减库存结束storage中");
//        //远程方法 扣减账户余额
//        log.info("------->扣减账户开始account中");
//        result = accountApi.prepare(actionContext, order.getUserId(),order.getPayAmount());//账户服务prepare
//        log.info("------->扣减账户结束account中" + result);
//        log.info("------->交易结束");
//        return true;
//    }
}
